package com.cscec5b.inspection.controller;

import com.cscec5b.inspection.entity.Project;
import com.cscec5b.inspection.service.ProjectService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/projects")
//@lombok.extern.slf4j.Slf4j
public class ProjectController {

    private final ProjectService projectService;

    public ProjectController(ProjectService projectService) {
        this.projectService = projectService;
    }

    // GET /api/projects/my
//    @GetMapping("/my")
//    public List<Project> myProjects() {
//        return projectService.listMyProjects();
//    }

    @GetMapping("/my")
    public List<Project> my(jakarta.servlet.http.HttpSession session) {
        Object val = session.getAttribute("USER_CODE");
        if (val == null) throw new RuntimeException("未登录或会话失效");
        return projectService.listByUserCode(String.valueOf(val));
    }


}
